package com.thinkingstar.iads.projectcenter.controller;

import com.alibaba.fastjson.JSONObject;
import com.bstek.urule.runtime.KnowledgeSession;
import com.thinkingstar.iads.common.filter.GlobalsFilter;
import com.thinkingstar.iads.common.filter.UserLoginFilter;
import com.thinkingstar.iads.common.jsonUtils.AjaxResult;
import com.thinkingstar.iads.common.utils.*;
import com.thinkingstar.iads.cs.sys.entity.SysUser;
import com.thinkingstar.iads.datacenter.entity.*;
import com.thinkingstar.iads.datacenter.entity.common.dao.CommonDao;
import com.thinkingstar.iads.datacenter.entity.dao.*;
import com.thinkingstar.iads.datacenter.serviceImpl.DataDesignManagerServiceImpl;
import com.thinkingstar.iads.projectcenter.entity.PcProjectConstantData;
import com.thinkingstar.iads.projectcenter.entity.PcProjectFormulaData;
import com.thinkingstar.iads.projectcenter.entity.PcProjectInfo;
import com.thinkingstar.iads.projectcenter.entity.dao.DaoPcProjectData;
import com.thinkingstar.iads.projectcenter.serviceImpl.ProjectDesignManagerServiceImpl;
import com.thinkingstar.iads.test.urule.controller.RuleTool;
import org.apache.commons.lang3.StringUtils;
import org.nutz.dao.Cnd;
import org.nutz.dao.Dao;
import org.nutz.dao.QueryResult;
import org.nutz.dao.Sqls;
import org.nutz.dao.sql.Sql;
import org.nutz.dao.sql.SqlCallback;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.lang.util.NutMap;
import org.nutz.log.Log;
import org.nutz.log.Logs;
import org.nutz.mvc.annotation.*;

import com.thinkingstar.iads.projectcenter.serviceImpl.EquipmentBudgetServiceImpl;
import com.thinkingstar.iads.projectcenter.serviceImpl.ProjectDcsjServiceImpl;
import org.springframework.jmx.export.metadata.AbstractJmxAttribute;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.File;
import java.io.IOException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.*;

/**
 * 动车设计相关
 * @author z
 *
 */
@IocBean
@At("/projectCenter/designcell")
@Filters({ @By(type = GlobalsFilter.class) , @By(type = UserLoginFilter.class)})
public class ProjectDcsjController {
	
	private static Log log = Logs.get();

	@Inject
	private DaoDcFormField daoDcFormField;

	@Inject
	private com.thinkingstar.iads.datacenter.entity.common.dao.CommonDao CommonDao;

	@Inject
	private ProjectDesignManagerServiceImpl projectDesignManagerServiceImpl;

	@Inject
	private ProjectDcsjServiceImpl projectDcsjServiceImpl;

	@Inject
    private DaoDcProjectDesignFormulaVersion daoDcProjectDesignFormulaVersion;

	@Inject
	private DaoDcProjectDesignConstantVersion daoDcProjectDesignConstantVersion;

	@Inject
    private DaoDcProjectDesignCell daoDcProjectDesignCell;

	@Inject
	private DaoDcProjectMention daoDcProjectMention;

	@Inject
	private DataDesignManagerServiceImpl dataDesignManagerServiceImpl;
	
	@Inject
	private EquipmentBudgetServiceImpl equipmentBudgetServiceImpl;
	
	@Inject
	private DaoPcProjectData daoPcProjectData;
	
	@Inject
	private DaoDcProjectFieldWidget daoDcProjectFieldWidget;

	/**
	 * 点击动车设计 进入页面 （默认常量）
	 * */
	@At("/index/?/?/?")
	@Ok("beetl:/projectRoot/pcCenter/designCell/projectConstant.html")
	public NutMap index(String design_cell_id,String project_id , String data_id) {
		NutMap nutMap = new NutMap();
		nutMap.put("project_id", project_id);
        nutMap.put("design_cell_id", design_cell_id);
        nutMap.put("data_id", data_id);
		return nutMap;
	}

	/**
	 *查询常量集列表，带分页
	 * */
	@At("/constantData")
	@Ok("json:full")
	public NutMap constantData(@Param("..") NutMap param){
		String project_id = (String)param.get("project_id");
        String design_cell_id = (String)param.get("design_cell_id");
		QueryResult list = projectDcsjServiceImpl.getConstantVersionListPage(param);
		NutMap nutMap = new NutMap();
		nutMap.put("project_id", project_id);
		nutMap.put("design_cell_id", design_cell_id);
		nutMap.put("dataList",list);
		return nutMap;
	}

	/**
	 * 点击动车设计页面点公式
	 * */
	@At("/formulaIndex/?/?/?")
	@Ok("beetl:/projectRoot/pcCenter/designCell/projectFormula.html")
	public NutMap formulaIndex(String design_cell_id,String project_id , String data_id) {
		NutMap nutMap = new NutMap();
		nutMap.put("project_id", project_id);
        nutMap.put("design_cell_id", design_cell_id);
        nutMap.put("data_id", data_id);
		return nutMap;
	}

	/**
	 *查询公式集列表，带分页
	 * */
	@At("/formulaData")
	@Ok("json:full")
	public NutMap formulaData(@Param("..") NutMap param){
		//根据项目ID获取所有公式集
		String project_id = (String)param.get("project_id");
		String design_cell_id = (String)param.get("design_cell_id");
		QueryResult list = projectDcsjServiceImpl.getFormulaVersionListPage(param);
		NutMap nutMap = new NutMap();
		nutMap.put("project_id", project_id);
		nutMap.put("design_cell_id", design_cell_id);
		nutMap.put("dataList",list);
		return nutMap;
	}

	/**
	 * 1.一键取用点击
	 * 2.根据项目id获取设计内容和设计阶段
	 * 3.根据设计内容和设计阶段获取 符合条件的所有公式list1
	 * 4.根据项目id查询项目公式列表 list2
	 * 5.如果list2.size()>0 说明已经取用过
	 * 6.如果list2.size()=0 那么要把list1插入到项目公式表里去
	 * TODO
	 * */
	@At("/takeFormulaIS/?/?")
	@Ok("json")
	public AjaxResult takeFormulaIS(String design_cell_id,String project_id ) {
		//数据中心所有公式
		List<DcProjectDesignFormulaData> list = projectDcsjServiceImpl.getDcProjectFormulaDataListByDesignCell(design_cell_id,project_id);
		//项目中心所有公式
		List<PcProjectFormulaData> list2 = projectDcsjServiceImpl.getPcProjectFormulaData(design_cell_id,project_id);
		if (list2.size()==0) {//未取用过
			projectDcsjServiceImpl.insertFormulaBatch(list,project_id,design_cell_id);
		} else {//取用过
			//删掉项目中心所有常量
			projectDcsjServiceImpl.deletePcProjectFormulaBatch(project_id,design_cell_id);
			//然后将数据中心所有常量插入
			projectDcsjServiceImpl.insertFormulaBatch(list,project_id,design_cell_id);
		}
		return AjaxResult.success("取用成功");
	}

	/**
	 * 1.单个常量集取用点击 (公式集code)
	 * 2.根据项目id获取设计内容和设计阶段
	 * 3.根据设计内容和设计阶段和公式集code获取 符合条件的所有公式list1
	 * 4.根据项目id 、常量集code 查询项目公式列表 list2
	 * 5.如果list2.size()>0 说明已经取用过
	 * 6.如果list2.size()=0 那么要把list1插入到项目公式表里去
	 * */
	@At("/takeFormula/?/?/?/?")
	@Ok("beetl:/projectRoot/pcCenter/designCell/projectFormulaChild.html")
	public NutMap takeFormula(String project_id,String design_cell_id,String formula_table_code , String data_id) {
		//数据中心该常量集下的所有公式
		List<DcProjectDesignFormulaData> list = projectDcsjServiceImpl.getDcProjectFormulaDataList(project_id,formula_table_code);
		//项目中心该常量集下的所有公式
		List<PcProjectFormulaData> list2 = projectDcsjServiceImpl.getPcProjectFormulaDataList(project_id,formula_table_code);
		if (list2.size()==0) {//未取用过
			//将数据中心该数据集下的公式list插入项目中心
			projectDcsjServiceImpl.insertFormulaBatch(list,project_id,design_cell_id);
		} else {//取用过
			//删掉项目中心该常量集下所有公式
			projectDcsjServiceImpl.deletePcProjectFormulaByOne(project_id,formula_table_code);
			//然后将数据中心该公式集下所有公式插入项目中心
			projectDcsjServiceImpl.insertFormulaBatch(list,project_id,design_cell_id);
		}
		NutMap nutMap = new NutMap();
		nutMap.put("project_id",project_id);
		nutMap.put("design_cell_id", design_cell_id);
		nutMap.put("formula_table_code",formula_table_code);
		nutMap.put("data_id", data_id);
		return nutMap;

	}

	/**
	 * 获取某个公式集下的公式列表
	 * */
	@At("/getFormulaListPage")
	@Ok("json:full")
	public NutMap getFormulaListPage(@Param("..") NutMap param){
		//查询项目中心指定公式集下的公式列表
		QueryResult returnList = projectDcsjServiceImpl.getPcProjectFormulaDataListPage(param);
		NutMap nutMap = new NutMap();
		nutMap.put("dataList",returnList);
		nutMap.put("project_id",param.get("project_id"));
		nutMap.put("design_cell_id", param.get("design_cell_id"));
		nutMap.put("formula_table_code",param.get("formula_table_code"));
		return nutMap;
	}

	/**
	 * 1.一键取用点击
	 * 2.根据项目id获取设计内容和设计阶段
	 * 3.根据设计内容和设计阶段获取 符合条件的所有常量list1
	 * 4.根据项目id查询项目设计常量列表 list2
	 * 5.如果list2.size()>0 说明已经取用过
	 * 6.如果list2.size()=0 那么要把list1插入到项目设计常量表里去
	 * */
	@At("/takeConstantIS/?/?")
	@Ok("json")
	public AjaxResult takeConstantIS(String project_id,String design_cell_id ) {
		//数据中心所有常量
		List<DcProjectDesignConstant> list = projectDcsjServiceImpl.getDcProjectConstantListByDesignCell(project_id,design_cell_id);
		//项目中心所有常量
		List<PcProjectConstantData> list2 = projectDcsjServiceImpl.getPcProjectConstantDataList(project_id,design_cell_id);
		if (list2.size()==0) {//未取用过
			projectDcsjServiceImpl.insertConstantBatch(list,project_id,design_cell_id);
		} else {//取用过
			//删掉项目中心所有常量
			projectDcsjServiceImpl.deletePcProjectConstantBatch(project_id,design_cell_id);
			//然后将数据中心所有常量插入
			projectDcsjServiceImpl.insertConstantBatch(list,project_id,design_cell_id);
		}
		return AjaxResult.success("取用成功");
	}

	/**
	 * 1.单个常量集取用点击 (常量集code)
	 * 2.根据项目id获取设计内容和设计阶段
	 * 3.根据设计内容和设计阶段和常量集code获取 符合条件的所有常量list1
	 * 4.根据项目id 、常量集code 查询项目设计常量列表 list2
	 * 5.如果list2.size()>0 说明已经取用过
	 * 6.如果list2.size()=0 那么要把list1插入到项目设计常量表里去
	 * */
	@At("/takeConstant/?/?/?/?")
	@Ok("beetl:/projectRoot/pcCenter/designCell/projectConstantChild.html")
	public NutMap takeConstant(String project_id,String design_cell_id,String constant_table_code , String data_id) {
		//数据中心该常量集下的所有常量
		List<DcProjectDesignConstant> list = projectDcsjServiceImpl.getDcProjectConstantList(project_id,constant_table_code);
		//项目中心该常量集下的所有常量
		List<PcProjectConstantData> list2 = projectDcsjServiceImpl.getPcProjectConstantDataList(project_id,constant_table_code);
		if (list2.size()==0) {//未取用过
			//将数据中心该数据集下的常量list插入项目中心
			projectDcsjServiceImpl.insertConstantBatch(list,project_id,design_cell_id);
		} else {//取用过
			//删掉项目中心该常量集下所有常量
			projectDcsjServiceImpl.deletePcProjectConstantByOne(project_id,constant_table_code);
			//然后将数据中心该常量集下所有常量插入项目中心
			projectDcsjServiceImpl.insertConstantBatch(list,project_id,design_cell_id);
		}
		//查询项目中心指定常量集下的常量列表
	//	List<PcProjectConstantData> returnList = projectDcsjServiceImpl.getPcProjectConstantDataList(project_id,constant_table_code);
		NutMap nutMap = new NutMap();
		//nutMap.put("dataList",returnList);
		nutMap.put("project_id",project_id);
		nutMap.put("design_cell_id", design_cell_id);
		nutMap.put("constant_table_code",constant_table_code);
		nutMap.put("data_id", data_id);
		return nutMap;
	}

	/**
	 * 获取某个常量集下的常量列表
	 * */
	@At("/getConstantListPage")
	@Ok("json:full")
	public NutMap getConstantListPage(@Param("..") NutMap param){
		//查询项目中心指定常量集下的常量列表
		QueryResult returnList = projectDcsjServiceImpl.getPcProjectConstantDataListPage(param);
		NutMap nutMap = new NutMap();
		nutMap.put("dataList",returnList);
		nutMap.put("project_id",param.get("project_id"));
		nutMap.put("constant_table_code",param.get("constant_table_code"));
		nutMap.put("design_cell_id",param.get("design_cell_id"));
		return nutMap;
	}

	/**
	 * 保存常量
	 *
	 * */
	@At("/updateConstant")
	@Ok("json")
	public AjaxResult updateConstant(@Param("..") PcProjectConstantData pcProjectConstantData, HttpSession session) {
		if (pcProjectConstantData.getStandard_type().equals("null")) {
			pcProjectConstantData.setStandard_type("");
		}
		if (pcProjectConstantData.getCode_parent_name().equals("null")) {
			pcProjectConstantData.setCode_parent_name("");
		}
		SysUser user = (SysUser) session.getAttribute("userSession");
		pcProjectConstantData.setOprator(user.getLoginname());
		pcProjectConstantData.setUpdate_time(CommonDateUtil.getDateTime());
		pcProjectConstantData.setCreate_time(projectDcsjServiceImpl.getPcProjectConstantDataById(pcProjectConstantData.getId()).getCreate_time());
		return projectDcsjServiceImpl.updatePcProjectConstantData(pcProjectConstantData);
	}

	/**
	 * 编辑保存公式
	 *
	 * */
	@At("/updateFormula")
	@Ok("json")
	public AjaxResult updateFormula(@Param("..") PcProjectFormulaData pcProjectFormulaData,HttpSession session) {
		SysUser user = (SysUser) session.getAttribute("userSession");
		pcProjectFormulaData.setOperator(user.getLoginname());
		pcProjectFormulaData.setUpdate_time(CommonDateUtil.getDateTime());
		pcProjectFormulaData.setCreate_time(projectDcsjServiceImpl.getPcProjectFormulaDataById(pcProjectFormulaData.getId()).getCreate_time());
		return projectDcsjServiceImpl.updatePcProjectFormulaData(pcProjectFormulaData);
	}

	//点击进入动车设计tab栏
	@At("/dcsj/?/?")
	@Ok("beetl:/projectRoot/pcCenter/designCell/tab.html")
	public NutMap dcsj(String design_cell_id , String project_id){
		NutMap nutMap = new NutMap();
		nutMap.put("project_id", project_id);
		nutMap.put("design_cell_id", design_cell_id);
		return nutMap;
	}
	
	/**
	 * 点击设计单元 进入页面
	 * */
	@At("/dcsjInfo/?/?/?")
	@Ok("beetl:/projectRoot/pcCenter/designCell/designCell.html")
	public NutMap dcsjInfo(String design_cell_id,String project_id , String data_id) {
		NutMap nutMap = new NutMap();
		nutMap.put("project_id", project_id);
		nutMap.put("design_cell_id", design_cell_id);
		nutMap.put("data_id", data_id);
		//查询设计单元 表名
		DcProjectDesignCell dcProjectDesignCell = daoDcProjectDesignCell.fetch(design_cell_id);
		String table_name = new StringBuffer("dc_designcell_").append(dcProjectDesignCell.getDesign_cell_table_code()).toString();
		nutMap.put("t_name", table_name);
		String fields = "";
		List <NutMap> field_list = daoDcFormField.queryColumnListForDesignCell(table_name);
		for (int i=0;i<field_list.size();i++) {
			if (!field_list.get(i).get("field_name").equals("id") && !field_list.get(i).get("field_name").equals("project_id")){
				if (field_list.get(i).get("widget_type").equals("select")) {
					fields+=field_list.get(i).get("field_name").toString()+"-"+field_list.get(i).get("field_comment").toString()+",";
				}
			}
		}
		nutMap.put("select_fields",fields);
		return nutMap;
	}

	/**
	 * select初始化
	 * */
	@At("/initSelect/?/?/?")
	@Ok("json:full")
	public Object initSelect(String designcell_tablename,String field_name,String project_id){
		return projectDcsjServiceImpl.initSelect(designcell_tablename,field_name,project_id);
	}

	//导出计算结果excel（设计单元）
	@At("/exportJsData/?")
	public void exportExcelData(String json, HttpServletRequest req , HttpServletResponse rep){
		//查询设计单元 表名
		NutMap param = new NutMap();
		JSONObject jo = new JSONObject(JSONObject.parseObject(json));
		Set set = jo.keySet();
		Iterator<String> it = set.iterator();
		while (it.hasNext()) {
			String str = it.next();
			String value = jo.get(str).toString();
			param.addv(str,value);
		}
		DcProjectDesignCell dcProjectDesignCell = daoDcProjectDesignCell.fetch(param.get("design_cell_id").toString());
		String table_name = new StringBuffer("dc_designcell_").append(dcProjectDesignCell.getDesign_cell_table_code()).toString();
		//List <NutMap> field_list = daoDcFormField.queryHradListByTable(table_name);//表头
		List <NutMap> field_list = daoDcFormField.queryColumnListForDesignCell(table_name);
		List <DcProjectFieldWidget> widget_list = daoDcProjectFieldWidget.findWidgetByTableName(table_name);
		param.addv("table_name",table_name);
		QueryResult result =  CommonDao.findDesignCellDataByTableNameAndParam(param,widget_list);
		List <NutMap> data_list = (List<NutMap>) result.getList();
		String file_name = dcProjectDesignCell.getDesign_cell_table_name()+".xls";PictureUtil.createFileName("xls");
		List<Map> countList = daoDcFormField.countFieldByParam(field_list,param);
		try {
			File file = ExcelPoiUtil.createExcelAddCount(file_name, param.get("project_id").toString(), "设计单元", field_list, data_list,countList);
			DownloadFileUtil.downLoadFile(file, file_name, req, rep);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 点击设计单元 进房屋表设计单元页面
	 * */
	@At("/dcsjInfos/?/?")
	@Ok("beetl:/projectRoot/pcCenter/designCell/designCell.html")
	public NutMap dcsjInfos(String project_id , String data_id) {
		NutMap nutMap = new NutMap();
		//查询项目所属的规则信息
		PcProjectInfo pcProjectInfo = daoPcProjectData.fetch(project_id);
		DcProjectDesignCell dcProjectDesignCell = 
				daoDcProjectDesignCell.findDesignCellByName(pcProjectInfo.getProject_design_phase_id(), pcProjectInfo.getProject_design_content_id(), pcProjectInfo.getProject_design_major_id());
		String design_cell_id = dcProjectDesignCell!=null?dcProjectDesignCell.getId():"";
		String table_name = "dc_designcell_"+dcProjectDesignCell.getDesign_cell_table_code();
		nutMap.put("project_id", project_id);
		nutMap.put("design_cell_id", design_cell_id);
		nutMap.put("data_id", data_id);
		nutMap.put("t_name", table_name);
		return nutMap;
	}

	/**
	 *查询设计单元表页面，带分页
	 * */
	@At("/designCellTable")
	@Ok("json:full")
	public NutMap designCellTable(@Param("..") NutMap param){
		return projectDcsjServiceImpl.getDesignCellTable(param);
	}
	
	//设备概算
	@At("/equipmentBudget")
	@Ok("json:full")
	public NutMap equipmentBudget(@Param("..") NutMap param){
		return equipmentBudgetServiceImpl.getEquipmentBudgetTable(param);
	}
	
	//设备概算规则计算
	@At("/equipmntBudgetCaculate")
	@Ok("json:full")
	public AjaxResult equipmntBudgetCaculate(@Param("project_id") String project_id , @Param("table_name") String table_name){
		return equipmentBudgetServiceImpl.equipmentCaculate(project_id , table_name);
	}

	/**
	 * 设计单元计算
	 * */
	@At("/caculate/?/?")
	@Ok("json:full")
	public AjaxResult caculate(String design_cell_id,String project_id){
		NutMap nutMap = new NutMap();
		nutMap.put("project_id", project_id);
		nutMap.put("design_cell_id", design_cell_id);
		//根据设计单元id获取关联的公式计算规则路径
		DcProjectDesignCell designCell = projectDcsjServiceImpl.getDcProjectDesignCell(design_cell_id);
		String urule_path = designCell.getUrule_path();
		String table_name = "dc_designcell_"+designCell.getDesign_cell_table_code();

		//依赖多个公式集 少有
		List<DcProjectDesignFormulaVersion> formulaVersionList = new ArrayList<>();
		if (StringUtils.isNotEmpty(designCell.getFormula_version_ids())){
			String[] formulaIds = designCell.getFormula_version_ids().split(",");
			for (int i=0;i<formulaIds.length;i++) {
				DcProjectDesignFormulaVersion formulaVersion = null;
				formulaVersion = daoDcProjectDesignFormulaVersion.fetch(formulaIds[i]);
				formulaVersionList.add(formulaVersion);
			}
		}
		List<DcProjectDesignConstantVersion> constantVersionList = new ArrayList<>();
		if (StringUtils.isNotEmpty(designCell.getConstant_version_ids())){
			String[] constantIds = designCell.getConstant_version_ids().split(",");
			for (int i=0;i<constantIds.length;i++) {
				DcProjectDesignConstantVersion constantVersion = null;
				constantVersion = daoDcProjectDesignConstantVersion.fetch(constantIds[i]);
				constantVersionList.add(constantVersion);
			}
		}

		if (StringUtils.isNoneEmpty(urule_path)) {
		    String formulaCode = "";
			for(int i=0;i<formulaVersionList.size();i++){
				formulaCode += formulaVersionList.get(i).getFormula_table_code()+",";
			}

			String constantCode = "";
			for(int i=0;i<constantVersionList.size();i++){
				constantCode += constantVersionList.get(i).getConstant_table_code()+",";
			}

			Map<String, Object> param = new HashMap<>();
			param.put("project_id",project_id);
			param.put("formulaCode",formulaCode);
			param.put("constantCode",constantCode);
			param.put("tableName",table_name);//插入的设计单元表名

			PcProjectInfo pcProjectInfo = daoPcProjectData.fetch(project_id);
			if (pcProjectInfo.getProject_design_content_name().equals("动车运用所")){
				//如果计算是列车对数表计算，那么需要知道 枢纽工作量详情表 表名 数据来源
				List<DcProjectDesignCell> designCells = daoDcProjectDesignCell.query(Cnd.where("design_cell_table_name","like","枢纽工作量详情%").and("project_design_phase_id","=",designCell.getProject_design_phase_id()).and("project_design_content_id","=",designCell.getProject_design_content_id()));
				if (null!=designCells && designCells.size()>0) {
					param.put("lcdsb_name","dc_designcell_"+designCells.get(0).getDesign_cell_table_code());
				}
				//设计动车设施
				param.put("sjdcss_name",projectDesignManagerServiceImpl.getSjdcssTableName(designCell.getProject_design_phase_id(),designCell.getProject_design_content_id()));
			} else if(pcProjectInfo.getProject_design_content_name().equals("物资总库")){
				//项目主要技术标准表
				List<DcProjectMentionInformation> dcProjectMentionInformations = daoDcProjectMention.query(Cnd.where("mention_information_name","like","%项目专用信息%").and("del_flag","=","0"));
				if (null!=dcProjectMentionInformations && dcProjectMentionInformations.size()>0) {
					param.put("xmzyjsbz_name","dc_mention_"+dcProjectMentionInformations.get(0).getMention_information_code());
				}
				//综合维修中心工程车库计算 依赖于 车库股道数量表 （提入）
				List<DcProjectMentionInformation> dcProjectMentionInformations1 = daoDcProjectMention.query(Cnd.where("mention_information_name","like","%车库股道数量%").and("del_flag","=","0"));
				if (null!=dcProjectMentionInformations1 && dcProjectMentionInformations1.size()>0) {
					param.put("ckgdslb_name","dc_mention_"+dcProjectMentionInformations1.get(0).getMention_information_code());
				}
				//网箱托盘货物架数量计算 依赖于 货位数量计算表
				List<DcProjectDesignCell> designCells = daoDcProjectDesignCell.query(Cnd.where("design_cell_table_name","like","%货位数量%").and("project_design_phase_id","=",designCell.getProject_design_phase_id()).and("project_design_content_id","=",designCell.getProject_design_content_id()).and("del_flag","=","0"));
				if (null!=designCells && designCells.size()>0) {
					param.put("wzzkhwsl_name","dc_designcell_"+designCells.get(0).getDesign_cell_table_code());
				}
				//定员计算 需要 变电配电所个数 表
				List<DcProjectMentionInformation> dcProjectMentionInformations2= daoDcProjectMention.query(Cnd.where("mention_information_name","like","%变电配电所个数%").and("del_flag","=","0"));
				if (null!=dcProjectMentionInformations2 && dcProjectMentionInformations2.size()>0) {
					param.put("bdspdsgs_name","dc_mention_"+dcProjectMentionInformations2.get(0).getMention_information_code());
				}

				//机构定员汇总计算  依赖 提入的 综合维修中心组织机构表
				List<DcProjectMentionInformation> dcProjectMentionInformations3= daoDcProjectMention.query(Cnd.where("mention_information_name","like","%综合维修中心组织机构%").and("del_flag","=","0"));
				if (null!=dcProjectMentionInformations3 && dcProjectMentionInformations3.size()>0) {
					param.put("zhwxzxzzjg_name","dc_mention_"+dcProjectMentionInformations3.get(0).getMention_information_code());
				}
				//机构定员汇总计算  依赖 设计单元 定员详情计算表
				List<DcProjectDesignCell> designCells2 = daoDcProjectDesignCell.query(Cnd.where("design_cell_table_name","like","%定员详情计算%").and("project_design_phase_id","=",designCell.getProject_design_phase_id()).and("project_design_content_id","=",designCell.getProject_design_content_id()).and("del_flag","=","0"));
				if (null!=designCells2 && designCells2.size()>0) {
					param.put("dyxqjsb_name","dc_designcell_"+designCells2.get(0).getDesign_cell_table_code());
				}

			} else if(pcProjectInfo.getProject_design_content_name().equals("机务动车专业工作量计算")){
				//如果计算是列车对数表计算，那么需要知道 枢纽工作量详情表 表名 数据来源
				List<DcProjectDesignCell> designCells = daoDcProjectDesignCell.query(Cnd.where("design_cell_table_name","like","%枢纽动车组工作量计算详%").and("project_design_phase_id","=",designCell.getProject_design_phase_id()).and("project_design_content_id","=",designCell.getProject_design_content_id()));
				if (null!=designCells && designCells.size()>0) {
					param.put("lcdsb_name","dc_designcell_"+designCells.get(0).getDesign_cell_table_code());
				}
			}
			KnowledgeSession knowledgeSession = RuleTool.getSessionFactory(urule_path);
			knowledgeSession.fireRules(param);
			return AjaxResult.success();
		} else {
			return AjaxResult.error("无计算公式规则！");
		}
	}

}
